Skip to content

Compute mesh areas correctly for integer vertices - #39

Open
antonsoo wants to merge 2 commits into
nmwsharp:masterfrom
antonsoo:fix/integer-mesh-areas
Open

antonsoo wants to merge 2 commits into
nmwsharp:masterfrom
antonsoo:fix/integer-mesh-areas

Conversation

@antonsoo

Copy link
Copy Markdown

Integer vertices keep their dtype during edge subtraction and cross products in face_areas. Products can overflow and unsigned arithmetic can wrap, giving wrong face areas and, through vertex_areas, wrong vertex masses. For example, an int16 right triangle with 300-unit edges returns 12,232 instead of 45,000.

Widen integer coordinates before subtraction, then convert the resulting edges to floating point before taking cross products. The 64-bit case uses Python integers to retain small edges even at a large integer origin. Float inputs keep the existing arithmetic, and inputs are not mutated.

Add two regression methods covering all eight integer dtypes, both windings, float controls and translated 64-bit coordinates. All 13 project tests pass on Python 3.12/NumPy 2.5 with locally built Debug bindings and on Python 3.9/NumPy 1.26 with released 1.4.0 bindings and the current Python source. The patch changes no C++ code.

An additional audit of the included Bunny scan, using an independent Heron reference with 70-digit arithmetic, restores 24 incorrect area, mass and integration configurations. All 16 previously correct configurations remain byte-identical, including eight float controls. git diff --check passes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant